package zdream.pmfield.stage.director;

import zdream.pmfield.data.foe.VStat;
import zdream.pmfield.stage.buff.foe.FoeStageBuff;
import zdream.pmfield.stage.buff.StageBuff;

/**
 * 原名 Dice, 改名为 Roll
 *
 * @author Zdream
 * @date 2023-11-14
 * @since 0.0.1
 */
public class Roll {
	public VStat vStat;
	/**
	 * 状态等效果影响前的数值, 包含 FoeActor 的基础属性, 和技能的检定修正
	 */
	public short baseValue;
	/**
	 * <p>状态等效果影响后的数值
	 * <p>Roll influence based on stat.
	 * <p>ex. if stat = 80 and Accuracy = stat - 20 = 60, then baseValue = 80, fixedBaseValue = 60,
	 * you will have 60% chance to hit a roll
	 * </p>
	 */
	public short fixedBaseValue;
	/**
	 * 检定使用的随机数. 0 ~ 99
	 */
	public final short checkValue;
	/**
	 * 是否使用专注. 使用了专注的必定成功
	 */
	public boolean focus;
	public boolean result;

	public FoeStageBuff createdBy;
	public StageBuff<?> affectedBy;
	public transient boolean affectResult;

	public Roll(short checkValue) {
		this.checkValue = checkValue;
	}

	public Roll useFocus() {
		focus = true;
		result = true;
		return this;
	}

	public void refresh() {
		if (this.focus) {
			result = true;
			return;
		}

		if (this.affectedBy != null) {
			result = affectResult;
			return;
		}

		this.result = this.fixedBaseValue >= this.checkValue;
	}
}
